<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}设备管理系统{% endblock %}</title>
    
    <!-- 使用本地资源 -->
    <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/all.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/noto-sans-sc.css') }}" rel="stylesheet">
    
    <!-- 内联关键CSS -->
    <style>
        /* 只保留首屏渲染所需的关键CSS */
        :root {
            --primary-color: #007AFF;
            --secondary-color: #5856D6;
            --success-color: #34C759;
            --warning-color: #FF9500;
            --danger-color: #FF3B30;
            --info-color: #5AC8FA;
            --banner-color: #1C1C1E;
            --text-primary: #000000;
            --text-secondary: #3C3C43;
            --background-light: #F2F2F7;
            --border-color: #C6C6C8;
            --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
            --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
            --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
            --transition-speed: 0.2s;
        }
        
        body {
            font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
            background-color: var(--background-light);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            color: var(--text-primary);
            line-height: 1.6;
            -webkit-font-smoothing: antialiased;
        }
        
        /* 导航栏关键样式 */
        .navbar {
            background-color: rgba(28, 28, 30, 0.95);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            box-shadow: var(--shadow-sm);
            padding: 0.8rem 0;
        }
        
        .navbar-brand {
            font-weight: 700;
            color: white !important;
            font-size: 1.5rem;
            letter-spacing: 0.5px;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-right: 1rem;
            white-space: nowrap;
        }
        
        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            padding: 0.5rem 0.8rem !important;
            border-radius: 8px;
            font-weight: 500;
            font-size: 1rem;
            display: flex;
            align-items: center;
            gap: 0.3rem;
            white-space: nowrap;
            margin: 0 0.1rem;
        }

        /* 添加过渡动画 */
        .fade-in {
            animation: fadeIn 0.3s ease-in;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        /* 确保页脚始终在底部 */
        .footer {
            margin-top: auto;
            padding: 1rem 0;
            background-color: var(--background-light);
            border-top: 1px solid var(--border-color);
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .navbar-brand {
                font-size: 1.2rem;
            }
            
            .nav-link {
                padding: 0.4rem 0.6rem !important;
                font-size: 0.9rem;
            }
        }
    </style>
    
    {% block styles %}{% endblock %}
</head>
<body>
    {% if request.endpoint != 'login' %}
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container-xl">
            <a class="navbar-brand" href="{{ url_for('dashboard') }}">
                <i class="fas fa-server"></i> 设备管理系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link {% if request.path == url_for('dashboard') %}active{% endif %}" 
                           href="{{ url_for('dashboard') }}">
                            <i class="fas fa-tachometer-alt"></i> 仪表盘
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.path == url_for('inbound') %}active{% endif %}" 
                           href="{{ url_for('inbound') }}">
                            <i class="fas fa-arrow-down"></i> 设备入库
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.path == url_for('outbound') %}active{% endif %}" 
                           href="{{ url_for('outbound') }}">
                            <i class="fas fa-arrow-up"></i> 设备出库
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.path == url_for('discard') %}active{% endif %}" 
                           href="{{ url_for('discard') }}">
                            <i class="fas fa-trash"></i> 设备销库
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.path == url_for('inventory') %}active{% endif %}" 
                           href="{{ url_for('inventory') }}">
                            <i class="fas fa-boxes"></i> 库存管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.path == url_for('statistics') %}active{% endif %}" 
                           href="{{ url_for('statistics') }}">
                            <i class="fas fa-chart-bar"></i> 统计报表
                        </a>
                    </li>
                </ul>
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <span class="nav-link text-light">
                            <i class="fas fa-user"></i> {{ session.username }}
                        </span>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('change_password') }}">
                            <i class="fas fa-key"></i> 修改密码
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('logout') }}">
                            <i class="fas fa-sign-out-alt"></i> 退出
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    {% endif %}

    <!-- 消息提示 -->
    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for category, message in messages %}
                <div class="container">
                    <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                    </div>
                </div>
            {% endfor %}
        {% endif %}
    {% endwith %}

    <!-- 主要内容 -->
    <div class="container-xl main-content py-4 fade-in">
        {% block content %}{% endblock %}
    </div>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="container-xl text-center">
            <p class="mb-0">© 2024 Xuyangyixing. All rights reserved.</p>
        </div>
    </footer>

    <!-- 脚本优化 -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" defer></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" defer></script>
    <script>
        // 使用 requestIdleCallback 延迟执行非关键任务
        if ('requestIdleCallback' in window) {
            requestIdleCallback(function() {
                // 延迟加载非关键样式
                const styles = document.createElement('style');
                styles.textContent = `
                    /* 非关键CSS */
                    .card {
                        border: none;
                        border-radius: 16px;
                        box-shadow: var(--shadow-sm);
                        margin-bottom: 2rem;
                        transition: all var(--transition-speed) ease;
                        background: white;
                        overflow: hidden;
                    }
                    
                    .card:hover {
                        transform: translateY(-2px);
                        box-shadow: var(--shadow-md);
                    }
                    
                    /* 其他非关键样式... */
                `;
                document.head.appendChild(styles);
            });
        }

        // 优化页面加载动画
        document.addEventListener('DOMContentLoaded', function() {
            // 使用 IntersectionObserver 延迟加载图片
            if ('IntersectionObserver' in window) {
                const imageObserver = new IntersectionObserver((entries, observer) => {
                    entries.forEach(entry => {
                        if (entry.isIntersecting) {
                            const img = entry.target;
                            img.src = img.dataset.src;
                            observer.unobserve(img);
                        }
                    });
                });

                document.querySelectorAll('img[data-src]').forEach(img => {
                    imageObserver.observe(img);
                });
            }

            // 优化导航栏交互
            const navbarToggler = document.querySelector('.navbar-toggler');
            const navbarCollapse = document.querySelector('.navbar-collapse');
            
            if (navbarToggler && navbarCollapse) {
                navbarToggler.addEventListener('click', function() {
                    navbarCollapse.classList.toggle('show');
                });
            }

            // 使用 requestAnimationFrame 优化动画
            requestAnimationFrame(() => {
                document.body.classList.add('fade-in');
            });
        });
    </script>
    {% block scripts %}{% endblock %}
</body>
</html>